package com.teacold.customdemo.chapter_nine;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import com.teacold.customdemo.R;

public class SaveLayerUseExample extends View {
    private Paint mPaint;
    private Bitmap mBitmap;

    public SaveLayerUseExample(Context context) {
        this(context,null);
    }

    public SaveLayerUseExample(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public SaveLayerUseExample(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mPaint=new Paint();
        mPaint.setColor(Color.RED);
        mBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.dog);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(mBitmap,0,0,mPaint);
//        int layoutID=canvas.saveLayer(0,0,getWidth(),getHeight(),mPaint,Canvas.ALL_SAVE_FLAG);
        int layoutID=canvas.saveLayerAlpha(0,0,200,200,100,Canvas.ALL_SAVE_FLAG);
//        canvas.skew(1.732f,0);
//        canvas.drawRect(0,0,150,160,mPaint);
        canvas.drawColor(Color.WHITE);
        canvas.restoreToCount(layoutID);


    }
}
